package com.rongx.mapper;

import com.rongx.pojo.Emp;
import com.rongx.pojo.EmpQueryParam;
import org.apache.ibatis.annotations.*;

import java.time.LocalDate;
import java.util.List;
import java.util.Map;

@Mapper
public interface EmpMapper {

//    @Select("select e.*, d.name as deptName from emp e left join dept d on e.dept_id = d.id")
//    List<Emp> list();

    @Select("select count(*) from emp e left join dept d on e.dept_id = d.id ")
    Long count();

    // 关键修正：添加@Param注解指定参数名
//    @Select("select e.*, d.name deptName from emp as e left join dept as d on e.dept_id = d.id limit #{start}, #{pageSize}")
//    List<Emp> list(@Param("start") Integer start, @Param("pageSize") Integer pageSize);

//    @Select("select e.*, d.name deptName from emp as e left join dept as d on e.dept_id = d.id")
//    List<Emp> list();

//    public List<Emp> list(String name, Integer gender, LocalDate begin, LocalDate end);

    List<Emp> list(EmpQueryParam empQueryParam);


    @Options(useGeneratedKeys = true, keyProperty = "id")
    @Insert("insert into emp(username, name, gender, phone, job, salary, image, entry_date, dept_id, create_time, update_time) " +
            "values (#{username},#{name},#{gender},#{phone},#{job},#{salary},#{image},#{entryDate},#{deptId},#{createTime},#{updateTime})")
    void insert(Emp emp);

    void deleteByIds(List<Integer> ids);

    Emp getById(Integer id);

    void updateById(Emp emp);

    @MapKey("pos")
    List<Map<String, Object>> countEmpJobData();

    @MapKey("name")
    List<Map> countEmpGenderData();

    @Select("select * from emp where username = #{username} and password = #{password}")
    Emp getUsernameAndPassword(Emp emp);
}